package com.dongdongshop.controller;

import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.SellerService;
import com.dongdongsop.data.AjaxResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("seller")
public class SellerController {

    @DubboReference
    private SellerService sellerService;

    //跳转商家审核页面
    @RequestMapping("toSeller")
    public String toSeller(){
        return "admin/seller_1";
    }

    //查询商家审核
    @RequestMapping("sellerInfo")
    @ResponseBody
    public List<TbSeller> sellerInfo(){
        List<TbSeller> sellerList = sellerService.findSellerAll();
        return sellerList;
    }

    //跳转商家审核详情页
    @RequestMapping("toDetails")
    public String toDetails(String sellerId,Model model){
        TbSeller seller = sellerService.getSellerById(sellerId);
        model.addAttribute("seller",seller);
        return "seller/details";
    }

    //商家审核，修改商家的状态
    @RequestMapping("updateStatus")
    @ResponseBody
    public AjaxResult updateSellerStatus(TbSeller seller){
        try {
            int i = sellerService.updateSellerStatus(seller);
            return AjaxResult.OK().setData(i);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.ERROR();
        }
    }
}
